<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>五子棋登录页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/login.css">
    <script src="./js/jquery-3.6.1.min.js"></script>
</head>
<body>
    <div class="nav">
        <img src="./image/wuziqi.jpg" alt="">
        <span>五子棋对战</span>
        <div class="spaner">
        </div>
        <a href="register.html ">点击注册</a>
    </div>
    <div class="login-container">
        <!-- 登录页面对话框 -->
        <div class="login-dialog">
            <!-- 提示信息 -->
            <h3>登录</h3>
            <!-- 一行 -->
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" value="admin">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" value="admin">
            </div>
            <!-- 提交按钮 -->
            <div class="row">
                <button id="submit">登录</button>
            </div>
        </div>
    </div>
  
    <script>
        let usernameInput=document.querySelector('#username');
        let passwordInput=document.querySelector('#password');
        let submitButton=document.querySelector('#submit');
        submitButton.onclick=function(){
            $.ajax({
                type:'post',
                url:'/loginmd',
                data:{
                    username:usernameInput.value,
                    password:passwordInput.value,
                },
                success:function(data){
                    // 登录成功，返回当前user对象
                    // 登录失败，返回空user对象
                    if(data && data.status==1){
                        alert("登录成功!");
                        location.assign('/hall.html');

                    }else{
                    alert("登录失败,用户名或者密码错误");
                    $('#username').val("");
                    $('password').val("");
                    location.assign('/login.html');
                    }
                },
                error:function(){
                    alert("登录失败,用户名或者密码错误");
                    $('#username').val("");
                    $('password').val("");
                    location.assign('/login.html');
                }
            });
        }
    </script>
</body>
</html>